<?php
	error_reporting(E_ALL - E_NOTICE);
	require_once('config.php');
	header('Expires: -1');
	header('Connection: keep-alive');
	$admin = ($_GET['admin'] == sha1($_SERVER['REMOTE_ADDR'].md5($NAMIKO_WALL_ADMINPASS)));
	$cid = (int) $_POST['cid'];
	if($admin && $cid > 0){
		$db->autocommit(false);
		$db->query("INSERT INTO `deletion`(`cid`,`time`,`snap`,`ip`) SELECT `id`,NOW(),`content`,`ip` FROM `comment` WHERE `id`=$cid");
		$db->query("DELETE FROM `comment` WHERE `id` = $cid LIMIT 1");
		$db->commit();
		echo '1';
		exit();
	}
	if($_GET['ajax'] && sha1($NAMIKO_KEY.NAMIKO_WALL_SALT) == $_GET['key']){
		$from = (int) $_GET['last_id'];
		$to = (int) $_GET['first_id'];
		$reqtime = (int) $_GET['reqtime'];
		if($to > 0){
			$q = "`id` < $to";
			$limit = $NAMIKO_WALL_DISPLAY_EXTRA;
		}else{
			$q = "`id` > $from";
			$limit = $NAMIKO_WALL_LIMIT;
		}
		header('Content-Type: text/xml');
		$xml = new XMLWriter();
		$xml->openURI('php://output');
		$xml->setIndentString("\t");
		$xml->setIndent(true);
		$xml->startDocument('1.0','utf-8');
		$xml->startElement('namiko');
		$xml->writeAttribute('media', 'wall');
		$xml->writeAttribute('timestamp',time());
		$r = $db->query("SELECT `id`,`content`,TIME(`time`) AS `time` FROM `comment` WHERE $q ORDER BY `id` DESC LIMIT $limit");
		while($item = $r->fetch_assoc()){
			$xml->startElement('comment');
			$xml->writeAttribute('id', $item['id']);
			$xml->writeAttribute('time', $item['time']);
			$xml->text(htmlspecialchars($item['content']));
			$xml->endElement();
		}
		$d = $db->query("SELECT `cid` FROM `deletion` WHERE UNIX_TIMESTAMP(`time`) > $reqtime");
		while($item = $d->fetch_assoc()){
			$xml->startElement('deletion');
			$xml->writeAttribute('id', $item['cid']);
			$xml->endElement();
		}
		$xml->endElement();
		$xml->endDocument();
		$xml->flush();
		exit();
	}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-cn" dir="ltr">
<head><title>namiko wall</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="wall.css" />
</head>
<body>
<script language="javascript">
var key = "<?php echo sha1($NAMIKO_KEY.NAMIKO_WALL_SALT); ?>";
var refresh = <?php echo $NAMIKO_WALL_REFRESH; ?>;
var limit = <?php echo $NAMIKO_WALL_LIMIT; ?>;
var last_id = 0;
var first_id = 0;
var reqtime = <?php echo time(); ?>;
var extra = <?php echo $NAMIKO_WALL_DISPLAY_EXTRA; ?>;
var displayed = 0;
var admin = <?php echo $admin ? 'true' : 'false'; ?>;
var adminrefresh = <?php echo $NAMIKO_WALL_ADMIN_REFRESH; ?>;
var adminkey = "<?php echo $_GET['admin'] ?>";
</script>
<script type="text/javascript" src='wall.js'></script>
<h2>向现场大屏幕发送毕业感言1</h2>
<form action="submit.php" method="post" target="postframe" onsubmit="SendRefresh()">
<select name="fontname"><?php
	foreach($NAMIKO_FONTNAME as $FN => $FND){
		echo '<option value="'.$FN.'" ';
		if($_GET['fn'] == $FN) echo 'selected="selected"';
		echo ">$FND</option>";
	}
?></select>
<select name="fontsize"><?php
	foreach($NAMIKO_FONTSIZE as $FS => $FSD){
		echo '<option value="'.$FS.'" ';
		if($_GET['fs'] == $FS) echo 'selected="selected"';
		echo ">$FSD</option>";
	}
?></select>
<select name="fontcolor"><?php
	require_once('func.php');
	foreach($NAMIKO_FONTCOLOR as $FC => $FCD){
		echo '<option value="'.$FC.'" style="color: '.ColorConvert($FC).'" ';
		if($_GET['fc'] == $FC) echo 'selected="selected"';
		echo ">$FCD</option>";
	}
?></select>
<br /><textarea name="comment" id="CommentBox" onkeydown="CalcWord(this);if(event.keyCode==13&&event.ctrlKey) document.getElementById('ImageSubmitComment').click()"></textarea><br />
还可输入<span id="RemainingWord">500</span>字 <input id="ImageSubmitComment" type="image" src="button_submit.png" /><!--<a href="javascript:void(0)" onclick="alert(last_id)">XD</a> --><span id="StatusText"></span>
<br /><input type="hidden" name="fastreturn" value="true" /><input type="hidden" name="wall" value="true" /></form>
<iframe id="postframe" name="postframe" src="about:blank" border="0" style="display: none"></iframe>
<div id="WallContainer"></div>
<script language="javascript">
FetchNew();
</script>
</body>
</html>